package cc.atliberty.oa.controller;


import cc.atliberty.oa.service.DeptService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dept/delete")
public class DeleteDeptServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String deptno = request.getParameter("deptno");
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        DeptService deptService = context.getBean("deptService", DeptService.class);
        int i = deptService.deleteDept(deptno);
        if (i == 1){
            response.sendRedirect(request.getContextPath() + "/dept/list");
        }else {
            response.sendRedirect(request.getContextPath() + "error.jsp");
        }
    }
}
